/*
 *  NedAllocPolicy.h
 *  RTDemo
 *
 *  Created by steveca  on 13/05/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef __NED_ALLOC_POLICY_H__
#define __NED_ALLOC_POLICY_H__

namespace Sdlfw {
    
    // Ned allocator implementation wrapper
    class NedAllocImpl
        {
        public:
            static void *allocBytes(size_t size);
            static void *allocBytes(size_t size,
                                    const char *file, int line, const char *func);
            
            static void deallocBytes(void *ptr); 
            static void *allocBytesAligned(size_t align, size_t size, const char *file, int line, const char *func);
            static void deallocBytesAligned(size_t align, void *ptr);
            
        };
    
    class NedAllocPolicy
        {
        public:
            static inline void *allocateBytes(size_t size)
            {
                return NedAllocImpl::allocBytes(size);
            }
            
            static inline void *allocateBytes(size_t size, 
                                              const char *file = 0, int line = 0, const char *func = 0)
            {
                return NedAllocImpl::allocBytes(size,file,line,func);
            }
                        
            static inline void deallocateBytes(void *ptr)
            {
                NedAllocImpl::deallocBytes(ptr);
            }
        private:
            // No Instantiation
            NedAllocPolicy() {}
        };
    
    template <size_t Alignment = 0>
    class NedAlignedAllocPolicy
    {
    public:
        // compile-time check alignment is available.
        typedef int IsValidAlignment[Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1];

        static inline void *allocatedBytes(size_t size, 
                                           const char *file = 0, const int line = 0, const char *func = 0)
        {
            NedAllocImpl::allocBytesAligned(Alignment, size, file, line, func);
        }
    
        static inline void deallocBytes(void *ptr)
        {
            NedAllocImpl::deallocBytesAligned(Alignment, ptr);
        }
    
        static inline size_t getMaxAllocationSize()
        {
            size_t size = 0;
            
            return size;
        }
    private:
        NedAlignedAllocPolicy() {}
    
    };

}

#endif